"""
作者      :Anthnony Luo
创建时间   :2022/4/21 15:48
文件      :compare_data.py
IDE      :PyCharm

https://wenku.baidu.com/view/993c4745081c59eef8c75fbfc77da26925c59669.html
"""
import tkinter as tk
import tkinter.messagebox as mbox

root = tk.Tk()

#设置初始窗口大小
root.geometry('300x150')
root.title('比较数据的工具')

page = tk.Frame(root)
page.pack()


list1=tk.StringVar()
list2=tk.StringVar()

tk.Label(page,text="List1: ").grid(row=1,column=1)
tk.Entry(page,textvariable=list1).grid(row=1,column=2)

tk.Label(page,text="List2: ").grid(row=2,column=1,pady=10)
tk.Entry(page,textvariable=list2).grid(row=2,column=2)

def compare_data():
    dataStr1 = list1.get()
    dataStr2 = list2.get()

    data_list1 = dataStr1.split(',')
    data_list2 = dataStr2.split(',')
    print("data_list1",data_list1)
    print("data_list2",data_list2)
    if len(data_list1) > len(data_list2):
        data_list1,data_list2= data_list1,data_list2
    else:
        data_list1, data_list2 = data_list2, data_list1
    same_data = [i for i in data_list1 if i in data_list2]
    print(same_data)
    mbox.showinfo(title="共同的数据", message=same_data)

tk.Button(page,text="list中共同的数据",command=compare_data).grid(row=3,column=1)
tk.Button(page,text="退出",command=page.quit).grid(row=3,column=2)

#窗口可见
root.mainloop()
